package kuaizu.kuaizumqserver.config;

import kuaizu.common.mqconst.MQConstant;
import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static com.baomidou.mybatisplus.extension.ddl.DdlScriptErrorHandler.PrintlnLogErrorHandler.log;
@Log4j2
@Configuration
public class MQConfig{
    //初始化队列信息

    //创建队列
    @Bean
    public Queue projectSendQueue() {
        return new Queue(MQConstant.CREATE_PROJECT_QUEUE);
    }
    @Bean
    public Queue delectProjectQueue() {
        return new Queue(MQConstant.DELECT_PROJECT_QUEUE);
    }
    @Bean
    public Queue projectSendQueueDlx() {
        return new Queue(MQConstant.PROJECT_CREATE_SUBSCRIBE_QUEUE);
    }

    @Bean
    public Queue projectAuditQueue() {
        return new Queue(MQConstant.PROJECT_AUDIT_QUEUE);
    }

    @Bean
    public Queue projectAuditQueu1() {
        return new Queue(MQConstant.PROJECT_JOIN_QUEUE);
    }

    //
    //@Bean
    //public Queue projectSendQueueDlx() {
    //    return new Queue(MQConstant.PROJECT_SEND_QUEUE_DLX);
    //}


    //// 声明队列（durable=true表示持久化，autoDelete=false表示不自动删除）
    //@Bean
    //public Queue deadLetterQueue() {
    //    return QueueBuilder.durable(PROJECT_SEND_QUEUE_DLX)//创建持久化消息队列
    //            .withArgument("x-dead-letter-exchange", "your-dead-letter-exchange") // 如有死信交换机，需配置
    //            .build();
    //}

    //批量创建队列添加到
    //@Bean
    //public Queue[] queues() {
    //    Queue[] queues = new Queue[MQConstant.QUEUE_LIST.size()];
    //    for (int i = 0; i < MQConstant.QUEUE_LIST.size(); i++) {
    //        String queueName = MQConstant.QUEUE_LIST.get(i);
    //        log.info("创建队列：{}",queueName);
    //        queues[i] = QueueBuilder.durable(queueName).build(); // 使用
    //    }
    //    return queues;
    //}

    // 先测试单个队列
    @Bean
    public Queue testProjectSendQueue() {
        log.info("创建测试队列: {}", MQConstant.PROJECT_SEND_QUEUE);
        return QueueBuilder.durable("duil").build();
    }



}
